﻿@using xiushen.Domain
@using xiushen.Infrastructure
@model xiushen.Models.BookViewModel
<div class="well">
    <ul class="nav nav-tabs" id="cataegoryList">
        @foreach (var data in Model.RootCategories)
        {
            <li><a href="#@data.ID" data-toggle="tab">@data.Name</a></li>
        }
    </ul>
    <div class="tab-content">
        @foreach (var data in Model.RootCategories)
        {
            <text>
            <div class="tab-pane" id="@data.ID">
                <ul>
                    @{
                        Category data1 = data;
                        var datas = Model.AllCategorys.Where(r => r.ParentID == data1.ID);
                        foreach (var sub in datas)
                        {
                             <li><a href="@Url.Action("Books", new { id = sub.ID })" class="pull-left " style="padding-left: 10px;">@sub.Name</a></li>
                        
                        }
                    }
                </ul>
            </div>
            </text>
        }
    </div>
</div>
<div>
    共找到 @Model.TotalBook 部作品</div>
<ul class="breadcrumb">
    <li><a href="@Url.Action("Category")">国学</a> <span class="divider">/</span> </li>
    <li class="active">@Model.Category.Name</li>
</ul>
<ul>
    @{
        var books = Model.Category.Book.Paginate(Model.PageIndex, Constants.PAGESIZE);
        foreach (var data in books)
        {
            var hasContent = !string.IsNullOrEmpty(data.DirectContent);
            var actionName = "Chapters";
           if (hasContent)
              {
                  actionName = "BookContent";
              }
        <li>
            <h4>
                <a href="@Url.Action(actionName, new { bookId = data.ID, categoryId = Model.Category.ID, })">@data.Name</a>
            </h4>
            <span class="dashLine"></span>
            <div>
                作者：@data.Author 分类：@Model.Category.Name</div>
            <div class="description">
                @Html.Raw(data.Description)
            </div>
          
          
            <a href="@Url.Action(actionName, new { bookId = data.ID, categoryId = Model.Category.ID })" class="btn btn-info pull-right">
                阅读</a> <span class="dashLine"></span>
            </li>
        }
    }
</ul>
<div class="pagination pagination-centered">
    <ul>
        @if (Model.PageIndex > 1)
        {
            <li><a href="@Url.Action("Books", new { id = Model.Category.ID, pageIndex = Model.PageIndex - 1 })">
                上一页</a></li>
        }
        @{
            var firstPage = 1;
            var lastPage = Model.PageCount;

            if (Model.PageCount > 10)
            {
                firstPage = Model.PageIndex - 5;
                lastPage = Model.PageIndex + 5;
                if (lastPage < 10)
                {
                    lastPage = 10;
                }
            }
            if (lastPage > Model.PageCount)
            {
                lastPage = Model.PageCount;
            }
            if (firstPage <= 0)
            {
                firstPage = 1;
            }
            var pageCount = lastPage - firstPage;
            if (pageCount < 10)
            {
                firstPage = lastPage - 10;

            }
            if (firstPage <= 0)
            {
                firstPage = 1;
            }
            for (int i = firstPage; i <= lastPage; ++i)
            {
               
            <li  @if (i == Model.PageIndex)
                 {
                                    <text>class ="active" </text>
                 }><a href="@Url.Action("Books", new { id = Model.Category.ID, pageIndex = i })">@i</a></li>
            }
        }
        @if (Model.PageIndex < Model.PageCount)
        {
            <li><a href="@Url.Action("Books", new { id = Model.Category.ID, pageIndex = Model.PageIndex + 1 })">
                下一页</a></li>

        }
    </ul>
</div>
@section scripts
{
    <script type="text/javascript">
        $(document).ready(function () {
            $('#cataegoryList a').mouseover(function (e) {
                e.preventDefault();
                $(this).tab('show');
            });
            var selectedId = '#cataegoryList a[href="#@Model.Category.ParentID"]';
            $(selectedId).tab('show'); 
                });
      
    </script>
}
